package com.ysqcould.web.controller.message;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.message.domain.MemberAlbum;
import com.ysqcould.message.domain.bo.MemberAlbumBo;
import com.ysqcould.message.service.IMemberAlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员相册Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/message/album")
public class MemberAlbumController extends BaseController
{
    @Autowired
    private IMemberAlbumService memberAlbumService;

    /**
     * 查询会员相册列表
     */
    @PreAuthorize("@ss.hasPermi('message:album:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberAlbum memberAlbum)
    {
        startPage();
        List<MemberAlbum> list = memberAlbumService.selectMemberAlbumList(memberAlbum);
        return getDataTable(list);
    }

    /**
     * 导出会员相册列表
     */
    @PreAuthorize("@ss.hasPermi('message:album:export')")
    @Log(title = "会员相册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberAlbum memberAlbum)
    {
        List<MemberAlbum> list = memberAlbumService.selectMemberAlbumList(memberAlbum);
        ExcelUtil<MemberAlbum> util = new ExcelUtil<MemberAlbum>(MemberAlbum.class);
        util.exportExcel(response, list, "会员相册数据");
    }

    /**
     * 获取会员相册详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:album:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(memberAlbumService.selectMemberAlbumById(id));
    }

    /**
     * 新增会员相册
     */
    @PreAuthorize("@ss.hasPermi('message:album:add')")
    @Log(title = "会员相册", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberAlbum memberAlbum)
    {
        memberAlbum.setAsId(getUserId());
        return toAjax(memberAlbumService.insertMemberAlbum(memberAlbum));
    }

    /**
     * 修改会员相册
     */
    @PreAuthorize("@ss.hasPermi('message:album:edit')")
    @Log(title = "会员相册", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberAlbum memberAlbum)
    {
        return toAjax(memberAlbumService.updateMemberAlbum(memberAlbum));
    }

    /**
     * 删除会员相册
     */
    @PreAuthorize("@ss.hasPermi('message:album:remove')")
    @Log(title = "会员相册", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberAlbumService.deleteMemberAlbumByIds(ids));
    }

    /**
     * 删除单张相片
     * @param bo 相片
     * @return
     */
    @Log(title = "删除单张图片",businessType = BusinessType.DELETE)
    @DeleteMapping("/delImage")
    public AjaxResult delImage(@RequestBody MemberAlbumBo bo ){
      return toAjax( memberAlbumService.delImage(bo)) ;
    }
}
